//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by Apple on 2017/7/10.
//  Copyright © 2017年 KY. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //  提供便利构造函数创建对象
    convenience init(title: String, imageName: String? = nil, target: Any, action: Selector) {
        //  使用self调用其它构造函数
        let button = UIButton()
        //  添加点击事件
        button.addTarget(target, action: action, for: .touchUpInside)
        button.setTitle(title, for: .normal)
        //  图片不为空设置按钮的图片
        if imageName != nil {
            button.setImage(UIImage(named: imageName!), for: .normal)
        }
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.sizeToFit()
        self.init(customView: button)
    }
}
